package game.ui.controls
{
	import engine.asset.*;
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.text.*;
	import game.ui.core.*;
	
	public class RxTextLabel extends RxUIElement implements RxIDataRenderer
	{
		protected var m_textField:TextField;
		private var m_shadowField:TextField;
		private var m_background:Bitmap;
		private var m_overlay:Shape;
		protected var m_drawBackground:Boolean = false;
		protected var m_backgroundAlpha:Number;
		protected var m_backgroundColor:uint;
		protected var m_backgroundColorTransform:ColorTransform;
		protected var m_textColor:uint;
		protected var m_drawBorder:Boolean = false;
		protected var m_borderAlpha:Number;
		protected var m_borderColor:uint;
		protected var m_borderSize:int;
		protected var m_paddingTop:int = 0;
		protected var m_paddingBottom:int = 0;
		protected var m_paddingLeft:int = 0;
		protected var m_paddingRight:int = 0;
		protected var m_strike:Boolean;
		protected var m_strikeColor:uint;
		protected var m_cornerRadius:int = 0;
		protected var m_iconGap:int = 0;
		protected var m_icon:RxBitmap;
		protected var m_dataIndex:int;
		protected var m_data:Object;
		private var m_glowFilter:GlowFilter;
		private var m_dropShadowFilter:DropShadowFilter;
		
		public function RxTextLabel(param1:String = null, param2:Number = 16, param3:uint = 16777215, param4:Boolean = false, param5:String = "left", param6:Boolean = false)
		{
			this.m_textColor = param3;
			m_measuredWidth = 0;
			m_measuredHeight = 0;
			var _loc_7:* = new TextFormat();
			new TextFormat().size = param2;
			_loc_7.color = param3;
			_loc_7.bold = param4;
			_loc_7.rightMargin = 1;
			if (param5 != null)
			{
				_loc_7.align = param5;
			}
			if (param1 != null)
			{
				_loc_7.font = param1;
			}
			this.CreateTextField(_loc_7, param3, param6, param5);
			addChild(this.m_textField);
			mouseChildren = false;
			mouseEnabled = false;
		}
		
		protected function CreateTextField(param1:TextFormat, param2:uint, param3:Boolean, param4:String) : void
		{
			this.m_textField = new TextField();
			this.m_textField.defaultTextFormat = param1;
			this.m_textField.embedFonts = true;
			this.m_textField.selectable = false;
			this.m_textField.antiAliasType = AntiAliasType.ADVANCED;
			this.m_textField.textColor = param2;
			this.m_textField.multiline = param3;
			if (param4 != null)
			{
				this.m_textField.autoSize = param4;
			}
		}
		
		public function SetData(param1:Object) : void
		{
			var _loc_2:int = 0;
			var _loc_3:int = 0;
			var _loc_4:String = null;
			this.m_data = param1;
			if (this.m_data == null)
			{
				this.text = "";
				if (this.m_icon)
				{
					this.m_icon.url = "";
				}
			}
			else if (this.m_data is String)
			{
				this.text = this.m_data as String;
			}
			else
			{
				if (this.m_data.hasOwnProperty("htmlText"))
				{
					this.htmlText = this.m_data.htmlText;
				}
				else if (this.m_data.hasOwnProperty("text"))
				{
					this.text = this.m_data.text;
				}
				if (this.m_data.hasOwnProperty("color"))
				{
					this.textColor = this.m_data.color;
				}
				_loc_2 = 0;
				_loc_3 = 0;
				_loc_4 = null;
				if (this.m_data.hasOwnProperty("iconUrl"))
				{
					_loc_4 = this.m_data.iconUrl;
				}
				if (this.m_data.hasOwnProperty("iconWidth"))
				{
					_loc_2 = this.m_data.iconWidth;
				}
				if (this.m_data.hasOwnProperty("iconHeight"))
				{
					_loc_3 = this.m_data.iconHeight;
				}
				this.SetIconUrl(_loc_4, _loc_2, _loc_3);
			}
			InvalidateSize();
			this.UpdateDisplayState();
		}
		
		public function GetIconUrl() : String
		{
			if (this.m_icon)
			{
				return this.m_icon.url;
			}
			return "";
		}
		
		public function SetIconUrl(param1:String, param2:Number = NaN, param3:Number = NaN) : void
		{
			if (param1 == null)
			{
				return;
			}
			if (!this.m_icon)
			{
				this.m_icon = new RxBitmap();
				addChild(this.m_icon);
			}
			this.m_icon.addEventListener(Event.COMPLETE, this.OnBitmapLoaded);
			if (!isNaN(param2) && param2 > 0)
			{
				this.m_icon.width = param2;
			}
			if (!isNaN(param3) && param3 > 0)
			{
				this.m_icon.height = param3;
			}
			this.m_textField.visible = false;
			this.m_icon.url = param1;
			InvalidateSize();
		}
		
		protected function OnBitmapLoaded(event:Event) : void
		{
			this.m_icon.removeEventListener(Event.COMPLETE, this.OnBitmapLoaded);
			this.m_textField.visible = true;
			InvalidateSize();
			this.UpdateDisplayState();
		}
		
		
		public function set textColor(param1:uint) : void
		{
			this.m_textField.textColor = param1;
		}
		
		public function get textColor() : uint
		{
			return this.m_textField.textColor;
		}
		
		public function set htmlText(param1:String) : void
		{
			this.m_textField.htmlText = param1;
			var _loc_2:* = param1 != null && param1.indexOf("<a") != -1;
			this.ToggleHtmlLinkMouseCursors(_loc_2);
			InvalidateSize();
			this.UpdateDisplayState();
		}
		
		public function get htmlText() : String
		{
			return this.m_textField.htmlText;
		}
		
		public function GetData() : Object
		{
			return this.m_data;
		}
		
		public function SetDataIndex(param1:int) : void
		{
			this.m_dataIndex = param1;
			return;
		}
		
		public function GetDataIndex() : int
		{
			return this.m_dataIndex;
		}
		
		public function IsSelected() : Boolean
		{
			return false;
		}
		
		public function SetSelected(param1:Boolean) : void
		{

		}
		
		public function set text(param1:String) : void
		{
			this.ToggleHtmlLinkMouseCursors(false);
			if (this.text == param1)
			{
				return;
			}
			this.m_textField.text = param1;
			if (this.m_shadowField)
			{
				this.m_shadowField.text = param1;
			}
			InvalidateSize();
			this.UpdateDisplayState();
		}
		
		public function get text() : String
		{
			return this.m_textField.text;
		}
		
		protected function ToggleHtmlLinkMouseCursors(param1:Boolean) : void
		{
			if (param1)
			{
				addEventListener(MouseEvent.MOUSE_MOVE, this.OnMouseMove);
			}
			else
			{
				removeEventListener(MouseEvent.MOUSE_MOVE, this.OnMouseMove);
			}
			mouseChildren = param1;
			mouseEnabled = param1;
		}
		
		protected function OnMouseMove(event:MouseEvent) : void
		{
			var _loc_2:* = new Point(event.localX - this.m_textField.x, event.localY - this.m_textField.y);
			var _loc_3:* = this.m_textField.getCharIndexAtPoint(_loc_2.x, _loc_2.y);
			var _loc_4:* = this.m_textField.getTextFormat(_loc_3);
			if (this.m_textField.getTextFormat(_loc_3).url != "" && _loc_4.url != null)
			{
				RxUICursor.SetState(RxUICursor.INTERACTIVE, RxUICursorPriority.MEDIUM);
			}
			else
			{
				RxUICursor.SetState(null, RxUICursorPriority.MEDIUM);
			}
		}
		
		public static function CreateWithStyle(param1:String, param2:uint = 0, param3:String = "left", param4:Boolean = false) : RxTextLabel
		{
			var _loc_5:RxTextLabel = null;
			var _loc_6:* = RxFontLibrary.GetFontAttributesForStyle(param1);
			if (RxFontLibrary.GetFontAttributesForStyle(param1))
			{
				_loc_5 = new RxTextLabel(_loc_6.fontName, _loc_6.fontSize, param2, _loc_6.bold, param3, param4);
			}
			return _loc_5;
		}
		
		public function SetMultiline(param1:Boolean) : void
		{
			this.m_textField.multiline = param1;
		}
		
		public function SetTextFormat(param1:TextFormat) : void
		{
			this.m_textField.defaultTextFormat = param1;
			this.m_textField.autoSize = param1.align;
			this.m_textField.text = this.text;
		}
		
		public function SetStroke(param1:int, param2:uint) : void
		{
			if (param1 == 0)
			{
				this.m_textField.filters = null;
			}
			else
			{
				if (!this.m_glowFilter)
				{
					this.m_glowFilter = new GlowFilter();
				}
				this.m_glowFilter.blurX = 5;
				this.m_glowFilter.blurY = 5;
				this.m_glowFilter.strength = 10;
				this.m_glowFilter.color = param2;
				this.m_textField.filters = [this.m_glowFilter];
			}
		}
		
	}
}